package com.siruier.boss.ui.viewmodel

import androidx.annotation.MainThread
import androidx.lifecycle.*

/**
 * 全局viewmodel，可提供用户信息等全局信息;
 * viewmodel做全局有个问题，每次新的监听会收到以前的数据
 */
@MainThread
inline fun <reified VM : ViewModel> applicationViewModel() = ViewModelLazy(VM::class, { ApplicationViewModelStoreOwner.viewModelStore }, { ApplicationViewModelStoreOwner.applicationViewModelFactory })
class ApplicationViewModel : ViewModel() {
    val pushPathLiveData: MutableLiveData<String?> = MutableLiveData()
}

object ApplicationViewModelStoreOwner : ViewModelStoreOwner {
    private val mAppViewModelStore: ViewModelStore = ViewModelStore()
    private val mApplicationViewModelFactory = ViewModelProvider.NewInstanceFactory()
    override fun getViewModelStore() = mAppViewModelStore
    val applicationViewModelFactory get() = mApplicationViewModelFactory
}
